<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<script src="../../js/jquery-1.11.3.min.js"></script>
<script type="text/javascript">
	function addDataObject() {
		var datasourceid = $("#datasourceid").val();
		var name = $("#name").val();
		var description = $("#description").val();
		var type = $("#type").val();
		var classify = $("#classify").val();
		$
				.ajax({
					type : "POST",
					url : "${pageContext.request.contextPath}/DataObjectManage/DataObjectManageAction!addDataObject",
					data : {
						"datasourceid" : datasourceid,
						"name" : name,
						"description" : description,
						"type" : type,
						"classify" : classify
					},
					dataType : "json",
					success : function(data) {
						var table = $('<table class="newTable" border="1"></table>');

						var tt = $('<tr></tr>');
						var ttdataobjectid = $('<td></td>');
						ttdataobjectid.append("数据对象ID")
						tt.append(ttdataobjectid)
						var ttfield = $('<td></td>');
						ttfield.append("字段")
						tt.append(ttfield)
						var ttindex = $('<td></td>');
						ttindex.append("位置")
						tt.append(ttindex)
						var ttfieldtype = $('<td></td>');
						ttfieldtype.append("字段类型")
						tt.append(ttfieldtype)
						var ttfieldsize = $('<td></td>');
						ttfieldsize.append("字段长度")
						tt.append(ttfieldsize)

						var ttcbs = $('<td></td>');
						ttcbs.append("查询权限管理")
						tt.append(ttcbs)
						var ttcbr = $('<td></td>');
						ttcbr.append("展示权限管理")
						tt.append(ttcbr)
						var ttcbd = $('<td></td>');
						ttcbd.append("必选权限管理")
						tt.append(ttcbd)
						table.append(tt);

						for (var i = 0; i < data.length; i++) {
							var tr = $('<tr class="ttr"></tr>');

							var dataobjectid = $('<td class="dataobjectid"></td>');
							dataobjectid.append(data[i].dataobjectid);
							tr.append(dataobjectid);

							var field = $('<td class="field"></td>');
							field.append(data[i].field);
							tr.append(field);

							var index = $('<td class="index"></td>');
							index.append(data[i].index);
							tr.append(index);

							var fieldtype = $('<td></td>');
							fieldtype.append(data[i].fieldtype);
							tr.append(fieldtype);

							var fieldsize = $('<td></td>');
							fieldsize.append(data[i].fieldsize);
							tr.append(fieldsize);

							var cb_s = $('<td class="cb_s"></td>');
							var cbs = $('<input name="select" type="checkbox"/>');
							cb_s.append(cbs);
							tr.append(cb_s);

							var cb_r = $('<td class="cb_r"></td>');
							var cbr = $('<input name="result" type="checkbox"/>');
							cb_r.append(cbr);
							tr.append(cb_r);

							var cb_d = $('<td class="cb_d"></td>');
							var cbd = $('<input name="defult" type="checkbox"/>');
							cb_d.append(cbd);
							tr.append(cb_d);

							table.append(tr);
						}
						$("body").append(table);
						var btn = $('<button onclick="addData()"></button>');
						btn.append("提交2");
						$("body").append(btn);
					}
				});
	}

	function addData() {
		var str = "";
		for (var i = 0; i < $(".ttr").length; i++) {

			var tr = $(".ttr").eq(i);

			var dataobjectid = tr.children(".dataobjectid").text();
			var field = tr.children(".field").text();
			var cb_s = tr.children(".cb_s").find("input[name=select]").prop(
					"checked");
			var cb_r = tr.children(".cb_r").find("input[name=result]").prop(
					"checked");
			var cb_d = tr.children(".cb_d").find("input[name=defult]").prop(
					"checked");
			str += dataobjectid + ",";
			str += field + ",";
			str += cb_s + ",";
			str += cb_r + ",";
			str += cb_d + ",";
			str += "#"
		}
		$
				.ajax({
					type : "POST",
					url : "${pageContext.request.contextPath}/DataObjectManage/DataObjectManageAction!updateFieldFlag",
					data : {
						"str" : str
					},
					success : function(data) {
						alert("成功");
					}
				});
	}
</script>
</head>
<body>
	<div>
		<table border="1">
			<tr>
				<td>数据源ID</td>
				<td><input id="datasourceid" type="text" value=1></td>
			</tr>
			<tr>
				<td>对象别名</td>
				<td><input id="name" type="text" value="app用户测试表1"></td>
			</tr>
			<tr>
				<td>数据对象描述</td>
				<td><input id="description" type="text"
					value="select * from T_USER_INFO u,T_PERMISSION p where u.id=p.user_id"></td>
			</tr>
			<tr>
				<td>数据对象类型</td>
				<td><input id="type" type="text" value=2></td>
			</tr>
			<tr>
				<td>数据对象分类ID</td>
				<td><input id="classify" type="text" value=1></td>
			</tr>
			<tr>
				<td>----------</td>
				<td><input type="button" onclick="addDataObject()" value="添加"></td>
			</tr>
		</table>
	</div>
</body>
</html>